<template>
    <form @submit.prevent="login" action="/login" method="get">
        <input type="text" placeholder="请输入邮箱" v-model="email"><br>
        <input type="password" placeholder="密码" v-model="password"><br>
        <input type="submit">
    </form>
    <div v-show="showError">
        用户名或密码错
    </div>
</template>
<script  setup>
import {ref} from "vue"
import { useRouter, useRoute } from 'vue-router'
import axios from "../axios"

const router = useRouter()
const email=ref('john.doe@example.com')
const password=ref('password123')
const showError=ref(false)
async function login(){
    try {
        const resp=await axios("/login?email="+email.value+"&password="+password.value)

        showError.value=false
        localStorage.setItem('customer',JSON.stringify(resp.data))
        router.push({name:'home'})
    
    } catch (error) {
        showError.value=true
    }
}

</script>